require('../css/courdescription.less')
document.ready(function(){
    let footer=document.querySelector('#footer');
    // let back1=document.querySelector('#font10');
    // back1.addEventListener('click',function(){
    //     history.back()
  let video=document.querySelector('#video');
  let title=document.querySelector('#title')
  let caluli=document.querySelector('#caluli')
  let time=document.querySelector('#time')
    //     });
   let event=document.querySelector('#event');
   console.log(event)
    
     //这是courdescription课程详情的获取用户详情的区域的开始;
     getcourseDetail()
   function getcourseDetail(){
      let id=location.search.split('=')[1]
    //    console.log(id);
    //    http://139.9.177.51:8099/sports/courseDetail?id=3"
    axios.get(window.$$.username+`/sports/courseDetail?id=${id}`)
    .then(function(res){
     let ret=res.data;
    let   arr=ret.data.fragments;
    console.log(arr)
    if(ret.status===0){
 window.localStorage.setItem('userDetail',JSON.stringify(ret.data.fragments))
    let index=0;
    autoplay()
     function autoplay(){
        title.textContent=ret.data.desc;
        caluli.textContent=ret.data.calorie;
        time.textContent=ret.data.time;
        video.src=window.$$.username+arr[index].videoUrl;
        event.className="playcourse iconfont icon-zanting"
        setTimeout(function(){
            event.style.display="none"
        },2000)
     }
     video.addEventListener('ended',function(){
           index=(index+1)%4;
           autoplay(index)
          
     })
    
    }
     
        
    })
    .catch(function(error){
        console.log(error);
        
    })
}
let flag=true;
video.addEventListener('click',function(){
   if(flag){
    event.style.display="block"
    event.className="playcourse iconfont icon-kaishi";
    video.pause();
   }else{
     setTimeout(function(){
        event.style.display="none";
     },2000)
    event.className="playcourse iconfont icon-zanting";
    video.play();
   }
   flag = !flag;
})
event.addEventListener('click',function(){
    
    video.pause();
})
//这是五部区域的点击事件
    footer.addEventListener('click',function(){
     window.location.href="./curriculum.html?courseId="+location.search.split('=')[1];
          
    })
   
    
})